package gosu;

public abstract class DrawOp implements Comparable {
  // Gosu assumes that the drawOps will be ordered by the
  // z value first and secondly by the drawing order.
  // Since Java's PriorityQueue throws insertion order to the
  // wind, I have this counter hack to keep track of it.
  private static long counter = 0;

  protected int _clipX;
  protected int _clipY;
  protected int _clipWidth;
  protected int _clipHeight;
  private boolean _clipped;

  private long _id;

  public DrawOp() {
    _id = counter++;
  }

  public abstract double getZ();
  public abstract void execute();
  
  public int compareTo(Object o) {
    int result = Double.valueOf(getZ()).compareTo(((DrawOp) o).getZ());
    return (result != 0) ? result : Long.valueOf(_id).compareTo(((DrawOp) o)._id);
  }


  void clip(int x, int y, int width, int height) {
    _clipped = true;
    _clipX = x;
    _clipY = y;
    _clipWidth = width;
    _clipHeight = height;
  }


  boolean isClipped() { return _clipped; }
}
